package com.wms.controller;

import com.wms.dto.WarehouseDto;
import com.wms.dto.WarehouseIdAndNameDto;
import com.wms.dto.WarehousePageDto;
import com.wms.pojo.PageResult;
import com.wms.pojo.Result;
import com.wms.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;

    @GetMapping
    public Result pageQuery(WarehousePageDto dto){
        PageResult pageResult = warehouseService.pageQuery(dto);
        return Result.success(pageResult);
    }

    //添加仓库
    @PostMapping
    public Result saveWarehouse(@RequestBody WarehouseDto dto){
        warehouseService.saveWarehouse(dto);
        return Result.success();
    }

    //回显仓库
    @GetMapping("/{id}")
    public Result getWarehouseById(@PathVariable Integer id){
        WarehouseDto dto = warehouseService.getWarehouseById(id);
        return Result.success(dto);
    }

    //修改
    @PutMapping
    public Result updateById(@RequestBody WarehouseDto dto){
        warehouseService.updateWarehouseById(dto);
        return Result.success();
    }

    //删除
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        warehouseService.removeById(id);
        return Result.success();
    }

    //查询所有
    @GetMapping("/all")
    public Result getWarehouseAll(){
        List<WarehouseIdAndNameDto> list = warehouseService.getWarehouseAll();
        return Result.success(list);
    }
}
